package daoServiceImpl;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.Dao;
import com.ibatis.dao.client.DaoManager; 
import com.ibatis.dao.client.DaoManagerBuilder;

// sql_map_config.xml 읽어서 사용
public class DaoService {
private static DaoManager daoManager;
	
	private static DaoManager getDaoManager() {
		String daoXmlResource = "dao.xml";
		Reader reader = null; 
		
		if(daoManager == null) {
			try {
				reader = Resources.getResourceAsReader(daoXmlResource);
				daoManager = DaoManagerBuilder.buildDaoManager(reader);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return daoManager;
	}
	
	public static Dao getDao(Class inter) {
		return getDaoManager().getDao(inter);
	}
}
